<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","images":"/images","scheme":"Muse","version":"8.3.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
  </script>
<meta name="description" content="数值的拓展二进制和八进制分别用前缀0b(或0B) 和 0o(或0O) 表示 如果要将0b和0O前缀的字符串数值转为十进制，要使用Number方法 console.log(Number(&amp;#x27;0b111&amp;#x27;));&#x2F;&#x2F;7console.log(Number(&amp;#x27;0o10&amp;#x27;));&#x2F;&#x2F;8   Number.isFinite( ),Number.isNaN( ) Number">
<meta property="og:type" content="article">
<meta property="og:title" content="ES6 学习笔记-Numbers">
<meta property="og:url" content="http://example.com/2021/02/04/ES6/ES6-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-Numbers/index.html">
<meta property="og:site_name" content="Lawted&#39;s Blog">
<meta property="og:description" content="数值的拓展二进制和八进制分别用前缀0b(或0B) 和 0o(或0O) 表示 如果要将0b和0O前缀的字符串数值转为十进制，要使用Number方法 console.log(Number(&amp;#x27;0b111&amp;#x27;));&#x2F;&#x2F;7console.log(Number(&amp;#x27;0o10&amp;#x27;));&#x2F;&#x2F;8   Number.isFinite( ),Number.isNaN( ) Number">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-02-04T03:28:35.000Z">
<meta property="article:modified_time" content="2021-05-07T01:28:02.468Z">
<meta property="article:author" content="Lawted Wu">
<meta property="article:tag" content="ES6">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://example.com/2021/02/04/ES6/ES6-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-Numbers/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>
<title>ES6 学习笔记-Numbers | Lawted's Blog</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Lawted's Blog</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%95%B0%E5%80%BC%E7%9A%84%E6%8B%93%E5%B1%95"><span class="nav-number">1.</span> <span class="nav-text">数值的拓展</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%92%8C%E5%85%AB%E8%BF%9B%E5%88%B6"><span class="nav-number">1.1.</span> <span class="nav-text">二进制和八进制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Number-isFinite-Number-isNaN"><span class="nav-number">1.2.</span> <span class="nav-text">Number.isFinite( ),Number.isNaN( )</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Number-parseInt-Number-parseFloat"><span class="nav-number">1.3.</span> <span class="nav-text">Number.parseInt( ) ,Number.parseFloat( )</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Number-isInteger"><span class="nav-number">1.4.</span> <span class="nav-text">Number.isInteger( )</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Number-EPSILON"><span class="nav-number">1.5.</span> <span class="nav-text">Number.EPSILON</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E5%85%A8%E6%95%B4%E6%95%B0%E5%92%8CNumber-isSafeInteger"><span class="nav-number">1.6.</span> <span class="nav-text">安全整数和Number.isSafeInteger( )</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Math%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%A9%E5%B1%95"><span class="nav-number">1.7.</span> <span class="nav-text">Math对象的扩展</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-trunc"><span class="nav-number">1.7.1.</span> <span class="nav-text">Math.trunc( )</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BD%AE%E5%AD%90"><span class="nav-number">1.7.1.1.</span> <span class="nav-text">轮子</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-ceil"><span class="nav-number">1.7.2.</span> <span class="nav-text">Math.ceil()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-sign"><span class="nav-number">1.7.3.</span> <span class="nav-text">Math.sign()</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BD%AE%E5%AD%90-1"><span class="nav-number">1.7.3.1.</span> <span class="nav-text">轮子</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-cbrt"><span class="nav-number">1.7.4.</span> <span class="nav-text">Math.cbrt()</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BD%AE%E5%AD%90-2"><span class="nav-number">1.7.4.1.</span> <span class="nav-text">轮子</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-hypot"><span class="nav-number">1.7.5.</span> <span class="nav-text">Math.hypot()</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ES6%E7%9A%84%E6%96%B0%E6%96%B9%E6%B3%95"><span class="nav-number">1.8.</span> <span class="nav-text">ES6的新方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-expm1"><span class="nav-number">1.8.1.</span> <span class="nav-text">Math.expm1()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-log1p"><span class="nav-number">1.8.2.</span> <span class="nav-text">Math.log1p()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-log10"><span class="nav-number">1.8.3.</span> <span class="nav-text">Math.log10()</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BD%AE%E5%AD%90-3"><span class="nav-number">1.8.3.1.</span> <span class="nav-text">轮子</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Math-log2"><span class="nav-number">1.8.4.</span> <span class="nav-text">Math.log2()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0"><span class="nav-number">1.8.5.</span> <span class="nav-text">三角函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8C%87%E6%95%B0%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">1.9.</span> <span class="nav-text">指数运算符</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Lawted Wu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">67</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/LAWTED" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;LAWTED" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



        </div>
      </div>
        <div class="back-to-top animated" role="button" aria-label="Back to top">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="en">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/02/04/ES6/ES6-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-Numbers/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ES6 学习笔记-Numbers
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-02-04 11:28:35" itemprop="dateCreated datePublished" datetime="2021-02-04T11:28:35+08:00">2021-02-04</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:28:02" itemprop="dateModified" datetime="2021-05-07T09:28:02+08:00">2021-05-07</time>
      </span>

  
    <span class="post-meta-item" title="Views" id="busuanzi_container_page_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">Views: </span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="数值的拓展"><a href="#数值的拓展" class="headerlink" title="数值的拓展"></a>数值的拓展</h1><h2 id="二进制和八进制"><a href="#二进制和八进制" class="headerlink" title="二进制和八进制"></a>二进制和八进制</h2><p>分别用前缀0b(或0B) 和 0o(或0O) 表示</p>
<p>如果要将0b和0O前缀的字符串数值转为十进制，要使用Number方法</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>(<span class="string">&#x27;0b111&#x27;</span>));<span class="comment">//7</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>(<span class="string">&#x27;0o10&#x27;</span>));<span class="comment">//8</span></span><br></pre></td></tr></table></figure>


<h2 id="Number-isFinite-Number-isNaN"><a href="#Number-isFinite-Number-isNaN" class="headerlink" title="Number.isFinite( ),Number.isNaN( )"></a>Number.isFinite( ),Number.isNaN( )</h2><ul>
<li>Number.isFinite( )用来检查一个数值是否非无穷</li>
</ul>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isFinite(<span class="number">15</span>));</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isFinite(<span class="literal">NaN</span>));</span><br></pre></td></tr></table></figure>
<ul>
<li>Number.isNaN( )用来检查一个值是否NaN</li>
</ul>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isNaN(<span class="string">&#x27;true&#x27;</span>));</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isNaN(<span class="number">9</span>/<span class="literal">NaN</span>));</span><br></pre></td></tr></table></figure>
<p>他们和传统的isFinite( ) 和isNaN( ) 的区别在于，传统方法会将非数值的值转换为数值再判断，而这两个新方法只对数值有效，非数值一律返回false</p>
<h2 id="Number-parseInt-Number-parseFloat"><a href="#Number-parseInt-Number-parseFloat" class="headerlink" title="Number.parseInt( ) ,Number.parseFloat( )"></a>Number.parseInt( ) ,Number.parseFloat( )</h2><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.parseFloat(<span class="string">&#x27;12.345$&#x27;</span>)); <span class="comment">//12.345</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.parseInt(<span class="string">&#x27;12.345&#x27;</span>)); <span class="comment">//12</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">Number</span>.parseInt === <span class="built_in">parseInt</span> <span class="comment">// true</span></span><br></pre></td></tr></table></figure>
<p>和全局的方法一样，但是可以减少全局性方法，让语言逐步模块化</p>
<h2 id="Number-isInteger"><a href="#Number-isInteger" class="headerlink" title="Number.isInteger( )"></a>Number.isInteger( )</h2><p>判断一个数是不是整数，注意，因为JS中，整数和浮点数是同样的存储方法，所以3和3.0被视为同一个值</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isInteger(<span class="number">3</span> ));<span class="comment">//true</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isInteger(<span class="number">3.0</span>));<span class="comment">//true</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isInteger(<span class="number">3.1</span>));<span class="comment">//false</span></span><br></pre></td></tr></table></figure>


<h2 id="Number-EPSILON"><a href="#Number-EPSILON" class="headerlink" title="Number.EPSILON"></a>Number.EPSILON</h2><p>一个极小的常量</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.EPSILON.toFixed(<span class="number">20</span>));<span class="comment">//0.00000000000000022204</span></span><br></pre></td></tr></table></figure>
<p>部署一个误差检查函数</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">withinErrorMargin</span>(<span class="params">left,right</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Math</span>.abs(left-right)&lt;<span class="built_in">Number</span>.EPSILON;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(withinErrorMargin(<span class="number">0.2</span>+<span class="number">0.1</span>,<span class="number">0.3</span>));<span class="comment">//true</span></span><br></pre></td></tr></table></figure>


<h2 id="安全整数和Number-isSafeInteger"><a href="#安全整数和Number-isSafeInteger" class="headerlink" title="安全整数和Number.isSafeInteger( )"></a>安全整数和Number.isSafeInteger( )</h2><p>ES6引入了Number.MAX_SAFE_INTEGER 和 Number.MIN_SAFE_INTEGER 这两个常量，用来表示这个范围的上下限。</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Number</span>.MAX_SAFE_INTEGER === <span class="built_in">Math</span>.pow(<span class="number">2</span>,<span class="number">53</span>)-<span class="number">1</span></span><br><span class="line"><span class="built_in">Number</span>.MIN_SAFE_INTEGER === <span class="built_in">Number</span>.MAX_SAFE_INTEGER</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isSafeInteger(<span class="number">3</span>));</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isSafeInteger(<span class="number">1.2</span>));</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Number</span>.isSafeInteger(<span class="built_in">Number</span>.MAX_SAFE_INTEGER+<span class="number">1</span>));</span><br><span class="line"><span class="literal">true</span></span><br><span class="line"><span class="literal">false</span></span><br><span class="line"><span class="literal">false</span></span><br></pre></td></tr></table></figure>
<h2 id="Math对象的扩展"><a href="#Math对象的扩展" class="headerlink" title="Math对象的扩展"></a>Math对象的扩展</h2><h3 id="Math-trunc"><a href="#Math-trunc" class="headerlink" title="Math.trunc( )"></a>Math.trunc( )</h3><p>用来去除一个数的小数部分，返回整数部分</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.trunc(<span class="number">4.1</span>) <span class="comment">//4</span></span><br><span class="line"><span class="built_in">Math</span>.trunc(<span class="string">&#x27;123.345&#x27;</span>) <span class="comment">//123 会先用Number转换为数值</span></span><br></pre></td></tr></table></figure>
<p>对于空值会返回NaN</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.trunc(<span class="literal">NaN</span>); <span class="comment">//NaN</span></span><br><span class="line"><span class="built_in">Math</span>.trunc(<span class="string">&#x27;foo&#x27;</span>); <span class="comment">//NaN</span></span><br></pre></td></tr></table></figure>


<h4 id="轮子"><a href="#轮子" class="headerlink" title="轮子"></a>轮子</h4><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.trunc = <span class="built_in">Math</span>.trunc||<span class="function"><span class="keyword">function</span>(<span class="params">x</span>)</span>&#123;</span><br><span class="line">	<span class="keyword">return</span> x&lt;<span class="number">0</span>?<span class="built_in">Math</span>.ceil(x):<span class="built_in">Math</span>.floor(x);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h3 id="Math-ceil"><a href="#Math-ceil" class="headerlink" title="Math.ceil()"></a>Math.ceil()</h3><p>和Math.floor()相反</p>
<h3 id="Math-sign"><a href="#Math-sign" class="headerlink" title="Math.sign()"></a>Math.sign()</h3><p>用来判断一个数是正数负数还是0</p>
<ul>
<li>正数返回1</li>
<li>负数返回-1</li>
<li>0返回0，-0返回-0</li>
<li>其他返回NaN</li>
</ul>
<h4 id="轮子-1"><a href="#轮子-1" class="headerlink" title="轮子"></a>轮子</h4><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.sign() = <span class="built_in">Math</span>.sign || <span class="function"><span class="keyword">function</span>(<span class="params">x</span>)</span>&#123;</span><br><span class="line">    x = +x; <span class="comment">//converting to a number</span></span><br><span class="line">    <span class="keyword">if</span>(x===<span class="number">0</span>||<span class="built_in">isNaN</span>(x))&#123;</span><br><span class="line">        <span class="keyword">return</span> x;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> x &gt; <span class="number">0</span> ? <span class="number">1</span> : -<span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>




<h3 id="Math-cbrt"><a href="#Math-cbrt" class="headerlink" title="Math.cbrt()"></a>Math.cbrt()</h3><p>cuberoot</p>
<h4 id="轮子-2"><a href="#轮子-2" class="headerlink" title="轮子"></a>轮子</h4><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.cbrt = <span class="built_in">Math</span>.cbrt || <span class="function"><span class="keyword">function</span>(<span class="params">x</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">var</span> y = <span class="built_in">Math</span>.pow(<span class="built_in">Math</span>.abs(x),<span class="number">1</span>/<span class="number">3</span>);</span><br><span class="line">  <span class="keyword">return</span> x&gt;<span class="number">0</span>?y:-y;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>


<h3 id="Math-hypot"><a href="#Math-hypot" class="headerlink" title="Math.hypot()"></a>Math.hypot()</h3><p>返回所有参数的平方和的平方根，类似勾股</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.hypot(<span class="number">3</span>,<span class="number">4</span>); <span class="comment">//5</span></span><br></pre></td></tr></table></figure>


<h2 id="ES6的新方法"><a href="#ES6的新方法" class="headerlink" title="ES6的新方法"></a>ES6的新方法</h2><h3 id="Math-expm1"><a href="#Math-expm1" class="headerlink" title="Math.expm1()"></a>Math.expm1()</h3><p>Math.expm1(x)  = Math.exp(x)-1</p>
<h3 id="Math-log1p"><a href="#Math-log1p" class="headerlink" title="Math.log1p()"></a>Math.log1p()</h3><p>Math.log1p(x) = Math.log(1+x)</p>
<h3 id="Math-log10"><a href="#Math-log10" class="headerlink" title="Math.log10()"></a>Math.log10()</h3><p>返回以10为底的x的对数，如果x小于0，返回NaN</p>
<h4 id="轮子-3"><a href="#轮子-3" class="headerlink" title="轮子"></a>轮子</h4><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.log10 = <span class="built_in">Math</span>.log10||<span class="function"><span class="keyword">function</span>(<span class="params">x</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Math</span>.log/<span class="built_in">Math</span>.LN10;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>


<h3 id="Math-log2"><a href="#Math-log2" class="headerlink" title="Math.log2()"></a>Math.log2()</h3><p>返回以2为底的x的对数，如果x小于0，返回NaN</p>
<h3 id="三角函数"><a href="#三角函数" class="headerlink" title="三角函数"></a>三角函数</h3><ul>
<li>Math.sinh(x)</li>
<li>Math.cosh(x)</li>
<li>Math.tanh(x)</li>
</ul>
<h2 id="指数运算符"><a href="#指数运算符" class="headerlink" title="指数运算符"></a>指数运算符</h2><p>指数运算符 **</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="number">2</span> ** <span class="number">2</span> <span class="comment">//4</span></span><br><span class="line"><span class="number">2</span> ** <span class="number">3</span> <span class="comment">//8</span></span><br></pre></td></tr></table></figure>











    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/ES6/" rel="tag"># ES6</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/02/02/ES6/ES6-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-String/" rel="prev" title="ES6 学习笔记-String">
                  <i class="fa fa-chevron-left"></i> ES6 学习笔记-String
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/02/04/ES6/ES6-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-Arrays/" rel="next" title="ES6 学习笔记-Arrays">
                  ES6 学习笔记-Arrays <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lawted Wu</span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  


  <script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>


<script>
var options = {
  bottom: '64px', // default: '32px'
  right: '32px', // default: '32px'
  left: 'unset', // default: 'unset'
  time: '0.5s', // default: '0.3s'
  mixColor: '#fff', // default: '#fff'
  backgroundColor: '#fff',  // default: '#fff'
  buttonColorDark: '#000',  // default: '#100f2c'
  buttonColorLight: '#fff', // default: '#fff'
  saveInCookies: true, // default: true,
  label: ' ', // default: ''
  autoMatchOsTheme: true // default: true
}
const darkmode = new Darkmode(options);
darkmode.showWidget();
</script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  






  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
